<?php

class Valideur extends  CI_Controller{
    function __construct(){
        parent::__construct();
    
    // load helpers
    $this->load->helper('url');
  }
	  
  function index()
  {
    // display information for the view
    $data['title'] = "Admin: Gestion des  valideur";
    $data['headline'] = "Systeme de gestion de valideurs";
    $data['include'] = 'valideur_index';

    $this->load->view('admintemplate', $data);
  }

  function add()
  {
    $this->load->helper('form');
    
    // display information for the view
    $data['title'] = "Classroom: Add valideur";
    $data['headline'] = "Add a New valideur";
    $data['include'] = 'valideur_add';

    $this->load->view('admintemplate', $data);
  }

  function create()
  {
    $this->load->helper('url');
    
    $this->load->model('valideur_model','',TRUE);
    $this->valideur_model->addvalideur($_POST);
    redirect('valideur/add','refresh');
  }

  function listing()
  {
    $this->load->library('table');
    
    $this->load->model('valideur_model','',TRUE);
    $valideurs_qry = $this->valideur_model->listvalideurs();

    // generate HTML table from query results
    $tmpl = array (
      'table_open' => '<table border="0" cellpadding="3" cellspacing="0">',
      'heading_row_start' => '<tr bgcolor="#66cc44">',
      'row_start' => '<tr bgcolor="#dddddd">' 
      );
    $this->table->set_template($tmpl); 
    
    $this->table->set_empty("&nbsp;"); 
  
    $this->table->set_heading('', 'nom', 'prenom', 'email', 
        'tel');

  
    $table_row = array();
    foreach ($valideurs_qry->result() as $valideur)
    {
      $table_row = NULL;
      $table_row[] = '<nobr>' . 
        anchor('valideur/edit/' . $valideur->id, 'edit') . ' | ' .
        anchor('valideur/delete/' . $valideur->id, 'delete',
          "onClick=\" return confirm('Are you sure you want to '
            + 'delete the record for $valideur->nom?')\"") .
        '</nobr>';
      // replaced above :: $table_row[] = anchor('valideur/edit/' . $valideur->id, 'edit');
      $table_row[] = $valideur->nom;
      $table_row[] = $valideur->prenom;
      $table_row[] = mailto($valideur->email);
      $table_row[] = $valideur->tel;
      
      

      $this->table->add_row($table_row);
    }    

    $valideurs_table = $this->table->generate();
    
    // generate HTML table from query results
    // replaced above :: $valideurs_table = $this->table->generate($valideurs_qry);
    
    // display information for the view
    $data['title'] = "adminhome: valideur Listing";
    $data['headline'] = "valideur Listing";
    $data['include'] = 'valideur_listing';

    $data['data_table'] = $valideurs_table;

    $this->load->view('admintemplate', $data);
  }
  
  function edit()
  {
    $this->load->helper('form');

    $id = $this->uri->segment(3);
    $this->load->model('valideur_model','',TRUE);
    $data['row'] = $this->valideur_model->getvalideur($id)->result();

    // display information for the view
    $data['title'] = "Classroom: Edit valideur";
    $data['headline'] = "Edit valideur Information";
    $data['include'] = 'valideur_edit';

    $this->load->view('admintemplate', $data);
  }

  function update()
  {
    $this->load->model('valideur_model','',TRUE);
    $this->valideur_model->updatevalideur($_POST['id'], $_POST);
    redirect('valideur/listing','refresh');
  }

  function delete()
  {
    $id = $this->uri->segment(3);
    
    $this->load->model('valideur_model','',TRUE);
    $this->valideur_model->deletevalideur($id);
    redirect('valideur/listing','refresh');
  }

}
/* End of file valideur.php */
/* Location: ./system/application/controllers/valideur.php */
